<?php

/**
 * Description of consoleLogMessageAction
\* www.teuker.nl - mail@teuker.nl
 * 
 * @author francisc
 */

class consoleLogMessageAction extends sfAction {

    public function execute($request) {
        $this->getContext()->getConfiguration()->loadHelpers(array('I18N'));
        
        SqlEngineCore::get()->insert(
                    array('table' => 'console_log',
                          'columns' => array(
                                'user_id' => $this->getUser()->getAttribute('user_id'),
                                'restaurant_id' => $this->getUser()->getAttribute('current_restaurant_id'),
                                'reservation_id' => $request->getParameter('reservation_id'),
                                'type' => $request->getParameter('type'),
                                'message' => $request->getParameter('message'),
                                'date_time_seen' => 'NOW()',
                                'created_at' => 'NOW()')));
        
        $user = SqlEngine::getUser(array('id' => $this->getUser()->getAttribute('user_id')));
        
        $message = __('Seen by user') . ': ' . $user[0]['name_first'] . ' ' . $user[0]['name_last'] . ' ' . __('at:') . date('H:i');
        /* also log it in the reservation log */
        SqlEngineCore::get()->insert(
                    array('table' => 'reservation_log',
                          'columns' => array(
                                'user_id' => $this->getUser()->getAttribute('user_id'),
                                'reservation_id' => $request->getParameter('reservation_id'),
                                'message' => $message,
                                'created_at' => 'NOW()')));

        return sfView::NONE;
    }
}
